<?php 
class agentClassAction extends Action
{
	public function defaultAction()
	{
		
	}
	
	public function dataAction()
	{
		$table = 'agent';
		$where = 'and `platid`='.$this->adminid.'';
		$where = '';
		$sql 	= 'select * from [Q]'.$table.' where 1=1 '.$where.'';
		$total	= 0;
		$rows	= $this->db->getall($sql);
		
		$uobj  	= m('file');
		foreach($rows as $k=>$rs){
			$rows[$k]['fileshu'] = $uobj->rows('`agentid`='.$rs['id'].'');
		}
		
		$barr = array(
			'rows' => $rows,
			'totalCount'=> $total,
			'success' => true
		);
		return $barr;
	}
	
	public function formAction()
	{	
		$id = (int)$this->get('id','0');
		$this->smartydata['id'] = $id;
			
		$fields = c('fields')->getArr('agent');
		$rs 	= $fields['data'];
		$fobj 	= $fields['fieldsobj'];
		$rs['picurlpic'] = 'images/noimg.jpg';
		
		if($id>0){
			$rs 	= m('agent')->getone('`id`='.$id.'');
			$rs['picurlpic'] = 'images/noimg.jpg';
			if(!isempt($rs['picurl']))$rs['picurlpic'] = $rs['picurl'];
		}
		
		$this->assign('fieldsobj', $fobj);
		$this->assign('data', $rs);
	}
	
	public function savecheckAction()
	{
		$id = (int)$this->post('id','0');
		$uarr= array(
			'name' 		=> $this->post('name'),
			'platid' 	=> $this->adminid,
			'picurl' 	=> $this->post('picurl'),
			'uptype' 	=> $this->post('uptype'),
			'callurl' 	=> $this->post('callurl'),
			'status' => 1,
			'optdt' => $this->rock->now
		);
		$where = '`id`='.$id.' and `platid`='.$this->adminid.'';
		if($id==0){
			$where = '';
			$uarr['agentkey'] = $this->db->ranknum('[Q]agent','agentkey',10);
		}
		$bo 	= m('agent')->record($uarr, $where);
		if(!$bo)return $this->db->error();
		
		return 'ok';
	}
	
}